<template>
  <div class="page">
    <p>useOverflow：打开弹窗 消除外部的滚动条</p>
    <button style="margin-top: 20px" @click="handleChange">打开弹窗</button>
  </div>
  <div v-if="visible" class="modal">
    <div class="modal-content">
      <button @click="handleChange">点我关闭</button>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue';
import { useOverflow } from '@/hooks/useOverflow';

const visible = ref(false);
const { setOverflowHidden, resetOverflow } = useOverflow(ref(document.body));
function handleChange() {
  if (visible.value) {
    resetOverflow();
  } else {
    setOverflowHidden();
  }
  visible.value = !visible.value;
}
</script>

<style scoped>
.page {
  height: 2000px;
}

.modal {
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: rgb(0 0 0 / 45%);
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1;
}

.modal-content {
  width: 600px;
  height: 400px;
  background-color: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>
